<?php

    $dev = null;
    foreach( $user->sharedRole as $role){
        if($role->id == 4)
            $dev = $user->id;
    }
    if(is_null($dev))
        jsonErrorDie("User has no rights to be added to group");

    $user->sharedGroupList[] = $group;
    $uid = R::store($user);
    $group->developers = addDeveloperGroup($user->id, $group);
    $gid = R::store($group);

    $now = R::isoDateTime();
    $a = R::dispense( 'gactivity');
    $a->user = $user;
    $a->group = $group;
    $a->dateFrom = $now;
    $a->dateTo = $now;
    $a = R::store( $a );

    if($gid != 0 && $uid != 0 ){
        $result["success"] = 'true';
        $result["message"] = 'Successfully added user';
        echo json_encode($result);
        die();
    }